home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gmp-132.lha / gmp-1.3.2 / mpz_mul_ui.c < prev    next >
C/C++ Source or Header  |  1993-05-02  |  2KB  |  79 lines

  1. /* mpz_mul_ui(product, multiplier, small_multiplicand) -- Set
  2.    PRODUCT to MULTIPLICATOR times SMALL_MULTIPLICAND.
  3.  
  4. Copyright (C) 1991 Free Software Foundation, Inc.
  5.  
  6. This file is part of the GNU MP Library.
  7.  
  8. The GNU MP Library is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. The GNU MP Library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with the GNU MP Library; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "gmp.h"
  23. #include "gmp-impl.h"
  24. #include "longlong.h"
  25.  
  26. void
  27. #ifdef __STDC__
  28. mpz_mul_ui (MP_INT *prod, const MP_INT *mult,
  29.         unsigned long int small_mult)
  30. #else
  31. mpz_mul_ui (prod, mult, small_mult)
  32.      MP_INT *prod;
  33.      const MP_INT *mult;
  34.      unsigned long int small_mult;
  35. #endif
  36. {
  37.   mp_size mult_size = mult->size;
  38.   mp_size sign_product = mult_size;
  39.   mp_size i;
  40.   mp_limb cy;
  41.   mp_size prod_size;
  42.   mp_srcptr mult_ptr;
  43.   mp_ptr prod_ptr;
  44.  
  45.   mult_size = ABS (mult_size);
  46.  
  47.   if (mult_size == 0 || small_mult == 0)
  48.     {
  49.       prod->size = 0;
  50.       return;
  51.     }
  52.  
  53.   prod_size = mult_size + 1;
  54.   if (prod->alloc < prod_size)
  55.     _mpz_realloc (prod, prod_size);
  56.  
  57.   mult_ptr = mult->d;
  58.   prod_ptr = prod->d;
  59.  
  60.   cy = 0;
  61.   for (i = 0; i < mult_size; i++)
  62.     {
  63.       mp_limb p1, p0;
  64.       umul_ppmm (p1, p0, small_mult, mult_ptr[i]);
  65.       p0 += cy;
  66.       cy = p1 + (p0 < cy);
  67.       prod_ptr[i] = p0;
  68.     }
  69.  
  70.   prod_size = mult_size;
  71.   if (cy != 0)
  72.     {
  73.       prod_ptr[mult_size] = cy;
  74.       prod_size++;
  75.     }
  76.  
  77.   prod->size = sign_product > 0 ? prod_size : -prod_size;
  78. }
  79.